﻿using System;
using ApplicationSettings.Pages;
using ApplicationSettings.Settings;
using ApplicationSettings.ViewModels;
using WinRTFramework.FrameworkConfiguration;

namespace ApplicationSettings.WinRTFrameworkConfiguration
{
    class ViewViewModelMapper : IViewViewModelMapper
    {
        private IIoCAdapter _ioCAdapter;

        public ViewViewModelMapper(IIoCAdapter ioCAdapter)
        {
            _ioCAdapter = ioCAdapter;
        }

        public Type GetViewTypeForViewModelType(Type viewModelType, object navigationParameter)
        {
            if (viewModelType == typeof(ContextSpecificSettingsDemoPageViewModel))
                return typeof (ContextSpecificSettingsDemoPage);

            if (viewModelType == typeof(MainPageViewModel))
                return typeof (MainPage);

            if (viewModelType == typeof(PermanentSettingsViewModel))
                return typeof(PermanentSettings);

            if (viewModelType == typeof(ContextSpecificSettingsViewModel))
                return typeof(ContextSpecificSettings);

            throw new ArgumentOutOfRangeException("viewModelType");
        }

        public object GetViewModelForView(Type viewType, object navigationParameter)
        {
            if (viewType == typeof(MainPage))
                return _ioCAdapter.GetInstanceOfType(typeof(MainPageViewModel));

            if (viewType == typeof(ContextSpecificSettingsDemoPage))
                return _ioCAdapter.GetInstanceOfType(typeof(ContextSpecificSettingsDemoPageViewModel));

            if (viewType == typeof(PermanentSettings))
                return _ioCAdapter.GetInstanceOfType(typeof(PermanentSettingsViewModel));

            if (viewType == typeof(ContextSpecificSettings))
                return _ioCAdapter.GetInstanceOfType(typeof(ContextSpecificSettingsViewModel));
            
            throw new ArgumentOutOfRangeException("viewType");
        }
    }
}
